package com.ssm.opa.common.base.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * rest工具类
 * <p/>
 * Copyright: Copyright (c) 2016年12月10日
 * <p/>
 * Company: 途牛科技有限公司华东分公司
 * <p/>
 *
 * @author lubin2
 * @project gtb-common
 */
public class TRestUtil {
	
	private static final Logger Logger = LoggerFactory.getLogger(TRestUtil.class);
	
	
	public static void writeJsonPAuto(HttpServletResponse response, String responseStr) {
		try {
			response.setHeader("Content-Type", "application/json;charset=UTF-8");
			response.setHeader("Access-Control-Allow-Origin", "*");
			response.getWriter().write(responseStr);
			response.getWriter().flush();
		} catch (IOException e) {
			Logger.error(responseStr, e);
		}
	}
	
	public static void writeBase64Data(HttpServletResponse response, String responseStr) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Content-Type", "application/json;charset=UTF-8");
		try {
			response.getWriter().write(Base64Util.encode(responseStr.getBytes("UTF-8")));
		} catch (IOException e) {
			Logger.error(responseStr, e);
		}
	}
}
